/*
 * Copyright 2007-2009 Perttu "celeron55" Ahola <celeron55@gmail.com>
 *
 * This file is part of jukumagic.
 *
 * jukumagic is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * jukumagic is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with jukumagic.  If not, see <http://www.gnu.org/licenses/>.
*/

#include "jukuobject.h"

#include <iostream>

JukuObject::JukuObject()
{
	//std::cout<<"JukuObject::JukuObject()"<<std::endl;
	m_owner = NULL;
	//m_id = OBJECT_ID_INVALID;
	//m_selected = false;
	m_flags = JUKUOBJECT_INITIAL_FLAGS;
	//m_ignore_changes = false;
}

JukuObject::~JukuObject()
{
	//std::cout<<"JukuObject::~JukuObject()"<<std::endl;
	//if(m_owner) m_owner->Remove(this);
}

void JukuObject::WriteBaseXML(TiXmlElement *element)
{
	//element->SetAttribute("id", m_id);
}

void JukuObject::ReadBaseXML(TiXmlElement *element)
{
	//element->Attribute("id", &m_id);
}

bool JukuObject::Add(JukuObject* object, JukuObject *prev_object)
{
	object->m_owner = this;
	return true;
}

void JukuObject::SetSelected(bool selected)
{
	bool old_selected = GetSelected();
	SetSelectedSilent(selected);
	if(old_selected != selected) ReportChange(OBJECT_CHANGE_SELECTION);
}

void JukuObject::SetSelectedSilent(bool selected)
{
	if(selected)
		m_flags |= JUKUOBJECT_SELECTED;
	else
		m_flags &= ~JUKUOBJECT_SELECTED;
}

void JukuObject::PrintList(std::list<JukuObject*> &objects)
{
	for(std::list<JukuObject*>::iterator i = objects.begin(); i != objects.end();){
		if((*i)->GetShortString()) std::cout<<(wxString((*i)->GetShortString()).mb_str(wxConvUTF8));
		else if((*i)->GetTypeString()) std::cout<<(wxString((*i)->GetTypeString()).mb_str(wxConvUTF8));
		i++;
		if(i != objects.end()){
			i++;
			if(i == objects.end()){
				std::cout<<" and ";
			}
			else std::cout<<", ";
			i--;
		}
	}
}



